<!DOCTYPE html>
<html lang="zh_CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>computedStyleMap</title>
    <style>
      a {
        --colour: red;
        color: var(--colour);
      }
    </style>
  </head>
  <body>
    <p>
      <a href="https://example.com">Link</a>
    </p>
    <dl id="regurgitation"></dl>
    <script>
      // get the element
      const myElement = document.querySelector('a')
      // get the <dl> we'll be populating
      const stylesList = document.querySelector('#regurgitation')
      // Retrieve all computed styles with computedStyleMap()
      const allComputedStyles = myElement.computedStyleMap()
      // iterate thru the map of all the properties and values, adding a <dt> and <dd> for each
      for (const [prop, val] of allComputedStyles) {
        // properties
        const cssProperty = document.createElement('dt')
        cssProperty.appendChild(document.createTextNode(prop))
        stylesList.appendChild(cssProperty)
        // values
        const cssValue = document.createElement('dd')
        cssValue.appendChild(document.createTextNode(val))
        stylesList.appendChild(cssValue)
      }
    </script>
  </body>
</html>
